﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Pay.Core;
using Pay.DTO;
using Pay.Services;

namespace Pay.Controllers
{
	/// <summary>
	/// 支付API
	/// </summary>
	[Route("api/[controller]")]
	[ApiController]
    [Authorize(AuthenticationSchemes = AuthHandler.SchemeName)]
    public class PayController : ControllerBase
	{
		private readonly IPayService _payService;
		private readonly string _baseUrl;

		/// <summary>
		/// ctor
		/// </summary>
		public PayController(IPayService payService)
		{
			_payService = payService;
			_baseUrl = $"{Request.Protocol}://{Request.Host}";
		}

		/// <summary>
		/// 支付
		/// </summary>
		[HttpPost("common_pay")]
		public async Task<LayuiResultDto<PayResponseDto>> CommonPayAsync(PayRequestDto model)
		{
			model.BaseUrl = _baseUrl;
			return await _payService.CommonPayAsync(model);
		}

		/// <summary>
		/// 退款
		/// </summary>
		[HttpPost("common_refund")]
		public async Task<LayuiResultDto<RefundResponseDto>> CommonRefundAsync(RefundRequestDto model)
		{
			model.BaseUrl = _baseUrl;
			return await _payService.CommonRefundAsync(model);
		}
    }
}